package cn.unknowpupil.init.utils.enter;

import java.util.HashMap;
import java.util.Map;


import cn.unknowpupil.init.utils.MapperUtils;
import cn.unknowpupil.init.utils.html.HttpUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * Created at 2020/10/29 by w10g <br>
 * Initialize EnterperiseUtils ... <br>
 *
 * @author unknowpupil
 * @since 0.0.1
 */
@Slf4j
public class EnterperiseUtils {
    /**
     * 获取accessToken
     * @param corpid
     * @param corpsecret
     * @return
     * @throws Exception
     */
    public static String getAccessToken(String corpid, String corpsecret) throws Exception {
        Map<String, String> param = new HashMap<String, String>();
        param.put("corpid", corpid);
        param.put("corpsecret", corpsecret);
        String accessToken = null;
        try {
            accessToken = HttpUtils.get("https://qyapi.weixin.qq.com/cgi-bin/gettoken", param);
        } catch (Exception e) {
            log.info("获取accessToken出错："+e);
        }
        Map<String, Object> map = MapperUtils.json2map(accessToken);

        return  map.get("access_token").toString();
    }
}
